package com.lh.rabbitmq.direct;

import com.lh.rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * 路由模式生产者
 */
public class Product {
    public static void main(String[] args) {
        try {
            Connection connection = RabbitMQUtils.getConnection();
            Channel channel = connection.createChannel();
            String exchangeName = "direct_exchange";
            // 声明交换机
            channel.exchangeDeclare(exchangeName, "direct");
            // 绑定队列  指定队列的路由键
            channel.queueBind("queue1", exchangeName, "email");
            channel.queueBind("queue2", exchangeName, "name");
            channel.queueBind("queue3", exchangeName, "age");
            // 发送消息
            channel.basicPublish(exchangeName, "email", null, new String("只发送给邮箱").getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
